package dataflow.core;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicBoolean;

import org.apache.log4j.Logger;

public class EventParser implements Runnable{

	static Logger log = Logger.getLogger(EventParser.class);
	
	private final LinkedBlockingQueue<IEvent> queue;
	private AtomicBoolean stop = new AtomicBoolean(false);
	
	public EventParser(LinkedBlockingQueue<IEvent> queue) {
		this.queue = queue;
	}
	
	
	@Override
	public void run() {
		try{
			while(!stop.get()){
				IEvent e = queue.take();
				e.execute();
			}
			
		}catch(InterruptedException ie){
			log.debug("Event parser interrupted", ie);
		} finally {
			log.debug("I'm leaving, arrivederci!");
		}
	}
	
	public void stop(){
		stop.set(true);
	}

}
